package com.gitee.huanminabc.demo.spring.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Author huanmin
 * @Date 2024/6/5 上午10:53
 */
@Component
@Aspect
public class DemoAop {

    //切入点 - 所有controller包下的所有方法
//    @Pointcut("execution(* com.gitee.huanminabc.demo.home.controller.*.*(..))")
    //切入点 - 注解拦截-所有方法上有@GetMapping注解的方法
//    @Pointcut("@annotation(org.springframework.web.bind.annotation.GetMapping)")
    //类注解
//    @Pointcut("@within(org.springframework.stereotype.Controller)")
    //方法注解和类注解
//    @Pointcut("@within(org.springframework.stereotype.Controller) && @annotation(org.springframework.web.bind.annotation.GetMapping)")
    public void pointcut() {
    }

    public void pointcut1() {
    }


//     @Before("pointcut()")  //前置通知
    //同时拦截多个切入点
//    @Before("pointcut() || pointcut1()")
     public void before() {
         System.out.println("before");
     }

//     @After("pointcut()")  //后置通知
     public void after() {
         System.out.println("after");
     }

//    @Around("pointcut()")   //环绕通知
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("around before");
        Object proceed = joinPoint.proceed();
        System.out.println("around after");
        return proceed;
    }

//    @AfterReturning("pointcut()") //返回通知
    public void afterReturning() {
        System.out.println("afterReturning");
    }

//    @AfterThrowing("pointcut()")  //异常通知
    public void afterThrowing() {
        System.out.println("afterThrowing");
    }



}
